package com.amsp.oa.oademo.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.amsp.oa.oademo.entity.MachineMaintenance;
import com.amsp.oa.oademo.service.MachineMaintenanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Api(tags = "机器设备维护记录管理")
@RestController
@RequestMapping("/api/machine-maintenance")
public class MachineMaintenanceController {

    @Autowired
    private MachineMaintenanceService machineMaintenanceService;

    @ApiOperation("根据机器ID获取维护记录")
    @GetMapping("/list/{machineId}")
    public List<MachineMaintenance> listByMachineId(@PathVariable Long machineId) {
        LambdaQueryWrapper<MachineMaintenance> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MachineMaintenance::getMachineId, machineId);
        return machineMaintenanceService.list(wrapper);
    }

    @ApiOperation("保存或更新维护记录")
    @PostMapping("/save")
    public boolean saveOrUpdate(@RequestBody MachineMaintenance machineMaintenance) {
        return machineMaintenanceService.saveOrUpdate(machineMaintenance);
    }

    @ApiOperation("批量保存或更新维护记录")
    @PostMapping("/batch-save")
    public List<MachineMaintenance> saveBatch(@RequestBody List<MachineMaintenance> records) {
        machineMaintenanceService.saveOrUpdateBatch(records);
        return records;
    }

    @ApiOperation("删除维护记录")
    @DeleteMapping("/{id}")
    public boolean delete(@PathVariable Long id) {
        return machineMaintenanceService.removeById(id);
    }

    @ApiOperation("批量删除维护记录")
    @DeleteMapping("/batch")
    public boolean deleteBatch(@RequestBody List<Long> ids) {
        return machineMaintenanceService.removeByIds(ids);
    }
}